﻿
CREATE PROCEDURE [dbo].[FirmSettingsUpdate]
(
	@Profile xml,
	@Note varchar(250),
	@MD datetime,
	@MW varchar(50),
	@Original_Id int,
	@Original_MD datetime
)
AS
DECLARE @strMsg nvarchar(500), @intRet int, @intErrCode int
	SET NOCOUNT ON

SELECT @intRet = Id
FROM [CO].[FirmSettings] WHERE Id = @Original_Id AND MD = @Original_MD
IF (@@rowcount <> 1)
BEGIN
	SELECT @intErrCode = 1, 
	@strMsg = 'Данные изменены после последнего запроса!'
	RAISERROR (@strMsg, 11, 1)
	RETURN @intErrCode
END

EXEC [dbo].[ProcessStatistic] @Note OUTPUT, @MD OUTPUT, @MW OUTPUT
	SET NOCOUNT OFF;
UPDATE [CO].[FirmSettings] SET [Profile] = @Profile,
[Note] = @Note, [MD] = @MD, [MW] = @MW 
WHERE Id = 1;
	
SELECT Id, [Profile], Note, MD, MW 
FROM [CO].[FirmSettings] WHERE (Id = 1)
RETURN 0
